****************************************************************************
*Replication File for Lyon and Kraft 2024
*Programming:    
	*Stata Version: Stata 16 SE 
	*Programmer: Mimi Lyon 
	*Last Modified: 2/27/2024
****************************************************************************

clear matrix
capture clear
capture log close
capture program drop _all
capture macro drop _all
drop _all
set more off
set scheme cleanplots
cd "/Users/ml212937/Dropbox (Brown)/Strikes Agenda Setting/Stata/" // you will need to change this to match your filepath 

***SWITCHES
global s1 "0" // SECTION 1: AD DESCRIPTIVES; Table A1 and Figure A1

global s2 "0" // SECTION 2: STRIKE AND AD DESCRIPTIVES; Figure A3, Figure 2 

global s3 "0" // SECTION 3: MAIN ANALYSIS, Table 1

global s4 "0" // SECTION 4: Robustness; Figure A4, Table A8

global s5 "0" // SECTION 5: MONTH LEVEL SENSITIVITY; Table A2

global s6 "0" // SECTION 6: MONTH LEVEL FIGURES; Figure 3, Figure 4, Figure 5

global s7 "0" // SECTION 7: FALSIFICATION; Table 5

global s8 "0" // SECTION 8: MONTH LEVEL HETEROGENEITY; Figure A5, Table 2, Table 3, Table A4, Table A13

global s9 "0" // SECTION 9: COST EXTENSION; Table A6

global s10 "0" // SECTION 10: ADDING MEDIA MARKET AND TIME-VARYING CONTROLS, Table A10, Table A11

global s11 "0" // SECTION 11: ANALYSIS OF DOWNSTREAM POLITICAL CONSEQUENCES; Table 4

global s12 "0" // SECTION 12: DOWNSTREAM SPENDING HETEROGENEITY; Table A7, Table C2 

global s13 "0" // SECTION 13: DOWNSTREAM SPENDING CONSEQUENCES; Figure 6

global s14 "0" // SECTION 14: DOWNSTREAM SPENDING CONSEQUENCES ROBUSTNESS; Table A12

global s15 "0" // SECTION 15: Drop Spillover Markets, Table A8

global s16 "0" // SECTION 16: INCUMBENT ANALYSIS; Table A5

global s17 "0" // SECTION 17: Union Campaign Contributions; Table A9 


***SECTION 1: AD DESCRIPTIVES; Table A1 and Figure A1
if $s1 == 1 {		
use "Data/strike_agenda_house_topost.dta", clear 

*generate valence measure
	gen count_pos = 1 if (adtone_promote==1 | cnt_prp==1) & issue50!=.
	gen count_neg = 1 if (adtone_attack==1 | cnt_prp==3) & issue50!=.
	foreach v of varlist count_pos  count_neg  {
	replace `v' =0 if `v'==.
}
***Figure A1
	sum issue50
	local mean = `r(mean)'
	preserve
	collapse issue50, by(state)
	sort issue50
	drop if state=="NATIONAL CABLE"
	graph bar issue50, over(state, sort(1)  label(angle(45) labsize(vsmall))) yscale(range(0(.10)1)) ylabel(0(.10) 1) ytitle("Portion of Ads Mentioning Education") yline(`mean')
	graph export Graphs/des_edmentions_state.jpg, as(jpg) replace
	restore

	
*Table A1
eststo clear 
		foreach v of varlist l est_cost time_* party_* sponsor_*  count_pos count_neg  {
		eststo sum_ed`v'2: estpost summarize `v' if issue50==1, detail
		eststo sum_ed`v'3: estpost summarize `v' if issue50==0, detail
		}
		esttab sum_ed* using Output/ed_characteristics.csv, replace  nogaps label cell("mean sd")
		
}

***SECTION 2: STRIKE AND AD DESCRIPTIVES; Figure A3, Figure 2 
if $s2 == 1 {
use "Data/strike_agenda_house_ym.dta", clear

*Figure 2  
	use "Data/strike_agenda_house_ym.dta", clear
	collapse (sum) count_ads , by(month)
	merge 1:1 month using Data/strike_month.dta, nogen
	rename subj strike_dist
	label var strike_dist "Teacher Strikes"
	gen ads = count_ads/4246782*100
	label var ads "U.S. House of Representative Election Ads"
		gen month1 = month - 0.4 // fixing the overlay problem 
		label var month1 "Month"
		label var month "Month"
		
	label define label_mon 1 "Jan." 2 "Feb." 3 "Mar." 4  "Apr." 5 "May" 6 "Jun." 7 "Jul." 8 "Aug." 9 "Sep." 10 "Oct." 11 "Nov." 12 "Dec.", replace
		label val month label_mon 
		label val month1 label_mon 
	
	graph twoway (bar strike month1, ytitle("Percent of Total") barw(0.4) xscale(range(1(1)12)) xlabel(1(1)12, valuelabel nogrid angle(45))  legend(row(1) order(1 2) pos(6))) (bar ads month, barw(0.4) )
		graph export "Graphs/LyonKraft-Figure-2.jpg", replace
	

	graph twoway (bar strike month1, ytitle("Percent of Total") barw(0.4) xscale(range(1(1)12)) xlabel(1(1)12, valuelabel nogrid angle(45) )  legend(row(1) order(1 2) pos(6))) (bar ads month, barw(0.4) scheme(plotplain) ) 
		graph export "Graphs/LyonKraft-Figure-2-BW.jpg", replace
	*/
		
*Figure A3: 
	use "Data/strike_agenda_house_ym.dta", clear
		collapse (count) strike_order , by(ym)
		label var strike_order "Number of Media Markets with Strikes"
			label var ym "Month"
		graph twoway (bar strike_order ym, barw(0.4)  xscale(range(564 706)) xlabel(570(6)706, nogrid format(%tmMon,_CCYY) angle(45))  legend(row(1) order(1 2) pos(6))) 
			graph export "Graphs/num_strikes_ym.jpg", replace
		
}

***SECTION 3: MAIN ANALYSIS, Table 1
if $s3 == 1 {
use "Data/strike_agenda_house_ym.dta", clear

*Table 1
*baseline means
	foreach v of varlist ed_ad ed_ad_pos ed_ad_neg  {
		sum `v' if treatXpost_cen==0 
		sum `v' if treatXpost_cen==0 & sens==1
		sum `v' if treatXpost_cen==0 & sens==0
	}
	 
	estimates clear

	foreach v of varlist ed_ad ed_ad_pos ed_ad_neg count_ed_ads count_pos_ed  count_neg_ed  {
		
	*main  
		reghdfe  `v' treatXpost_cen , absorb(ym market) vce(cluster market)
		eststo M_`v'_6
		
	* senstiive and non-sensitive time periods 
		reghdfe  `v' treatXpost_cen_sen treatXpost_cen_nonsen , absorb(ym market) vce(cluster market)
		eststo M_`v'_7
		test treatXpost_cen_sen = treatXpost_cen_nonsen 
		
	esttab M_* using Output/month_level.csv, replace label se keep(treatXpost_cen treatXpost_cen_sen treatXpost_cen_nonsen ) b(3) se(3) r2 ar2 star( + .10 * 0.05 ** 0.01 *** 0.001) nogaps

}

}

***SECTION 4: Robustness; Figure A4, Table A8
if $s4 == 1 {
*Table A8
	use "Data/strike_agenda_house_ym.dta", clear
		gen time=ym
		format time  %9.0g
		encode market, gen(dma)
		gen strike_never =(strikeever==0)
		
		estimates clear
		foreach v of varlist ed_ad ed_ad_pos ed_ad_neg   {

	*cohort stacked model
			preserve
		stackedev `v'  treatXpost_cen, cohort(strike_time) time(ym) never_treat(strike_never) unit_fe(dma) clust_unit(dma) 
			  eststo R_`v'_3
			restore

			preserve
		stackedev `v'  treatXpost_cen_sen treatXpost_cen_nonsen, cohort(strike_time) time(ym) never_treat(strike_never) unit_fe(dma) clust_unit(dma) 
			eststo R_`v'_4
			restore
		
			
	*regional time trends 
			reghdfe  `v' treatXpost_cen i.region#c.ym , absorb(ym market) vce(cluster market)
				eststo R_`v'_5
			
			reghdfe  `v' treatXpost_cen_sen treatXpost_cen_nonsen  i.region#c.ym , absorb(ym market) vce(cluster market)
				eststo R_`v'_6

	*region by year-month FE
		reghdfe  `v' treatXpost_cen count_ads , absorb(i.region#i.ym  market) vce(cluster market)
				eststo R_`v'_7
			
		reghdfe  `v' treatXpost_cen_sen treatXpost_cen_nonsen count_ads , absorb(i.region#i.ym  market) vce(cluster market)
				eststo R_`v'_8
	*state FE
		reghdfe  `v' treatXpost_cen count_ads , absorb(ym  market prim_state) vce(cluster market)
				eststo R_`v'_9
			
		reghdfe  `v' treatXpost_cen_sen treatXpost_cen_nonsen count_ads , absorb(ym  market prim_state) vce(cluster market)
				eststo R_`v'_10
				

	}

	esttab R_* using Output/month_robustness.csv, replace label se keep(treatXpost_cen treatXpost_cen_sen treatXpost_cen_nonsen ) b(3) se(3) r2 ar2 star( + .10 * 0.05 ** 0.01 *** 0.001) nogaps


*Figure A4
	*diagnostic plots: 
		twowayfeweights ed_ad dma time treatXpost_cen,  type(feTR) path(Data/weights) 
				 label save dma using Data/dma_labels, replace
					use "Data/weights.dta", clear // This shows the weight attached to each group*time cell. 
					sort weight G T
					run Data/dma_labels.do
					label val G dma 
					format T %tm
			scatter weight T, name(twowayfeweights, replace) // mlabel(G) 
				graph export Graphs/twfe_time_treatXpost_cen.jpg, as(jpg) replace
			

}
	
***SECTION 5: MONTH LEVEL SENSITIVITY; Table A2
if $s5 == 1 {
use "Data/strike_agenda_house_ym.dta", clear
	estimates clear
	 gen treatXpost_ec_late =(treatXpost_ec2==1 | treatXpost_ec3==1 | treatXpost_ec4==1 | treatXpost_ec5==1 | treatXpost_ec6==1)

			 
*Model Sensitivity
	foreach v of varlist ed_ad ed_ad_pos ed_ad_neg   {
	*first strike with later election cycles modeled separately 		
		reghdfe  `v' treatXpost_ec1 treatXpost_ec_late , absorb(ym market) vce(cluster market) 
			eststo S_`v'_1
			
		reghdfe  `v' treatXpost_ec1_sen treatXpost_ec1_nonsen  treatXpost_ec_late , absorb(ym market) vce(cluster market) 
			eststo S_`v'_2
			
		* first strike, treatment turned on for the whole post period
			reghdfe  `v' treatXpost , absorb(ym market) vce(cluster market)  
			eststo S_`v'_3

		*first strike, treatment turned on for the whole post period, sens/non-sen
			reghdfe  `v' treatXpost_sen treatXpost_nonsen , absorb(ym market) vce(cluster market)  
			eststo S_`v'_4
			
		}
	
use "Data/strike_agenda_house_ym.dta", clear
	drop t 
		sort market ym
		tab strike_order
		* now I want to stack 
		
		count 
		count if strike_time!=.
		
		foreach n of numlist 2/19 {
		gen strike_time`n'_tmp = ym if strike_order==`n'
		bysort market: egen strike_time`n'=max(strike_time`n'_tmp) // this will mark the timing of the nth strike
		count if strike_time`n'!=.
		}
		display 3312 + 1296 + 1152 + 1008 + 720 + 720 + 576 + (432*7) + 288 + (144*3) // 12,528
		
		
		*make a dataset of multiple strikes, only need to do this once 
		preserve 
				rename strike_time strike_time1
				drop strike_order
				keep if strikeever==1 & strike_time2!=. //only keeping observations in multiple strike districts 
				gen id=_n
				bro if market=="DETROIT" // just looking
				reshape long strike_time, i(id market ym) j(strike_order)
				drop if strike_time==. // dropping the extra ones
				drop if strike_order==1
				count 
				unique market 
				save Data/tostack_ym.dta, replace
		restore
			*/
			*append that dataset onto the main one
			replace strike_order=1 if strikeever==1
			append using Data/tostack_ym.dta
			sort market ym strike_time
			foreach n of numlist 2/19 {
				drop strike_time`n'					
				}
			drop *tmp
			replace strike_order=1 if strikeever==1 & strike_order==.
			
			*make market-by-event fixed effects
			encode market, gen(dma)
			replace dma=dma*dma*dma*dma //  get unique values of the market by event fixed effects, could do it differently but this works 
			gen marketXevent = dma*strike_order
			replace marketXevent= dma if strike_order==.
				bysort marketXevent: egen count_mbe=count(marketXevent) //check 
				tab count_mbe // okay all unique
			drop dma count_mbe
			
			*weights 
				gen mult_weight=1 
				bysort market: egen num_strike_time =max(strike_order)
				replace mult_weight = 1/num_strike_time if strike_order!=.

	*generate treatment variables				
	gen t = ym-strike_time
		*election year variables
			sort strike_order market ym election_yr
			gen el_yr1_tmp = election_yr if t[_n] == 0 & t[_n-1] == -1 // this is marking the election year of each strike
			bysort strike_order market: egen el_yr1 = max(el_yr1_tmp)
				gen el_yr2 = el_yr1 + 2
				gen el_yr3 = el_yr1 + 4
				gen el_yr4 = el_yr1 + 6
				gen el_yr5 = el_yr1 + 8
				gen el_yr6 = el_yr1 + 10
	replace t=-1 if t==. 
	
	bro if market=="LOS ANGELES"
	bro if market=="ABILENE"

	gen treatXpost_stack=(t>=0)
		replace treatXpost_stack=. if treatXpost_stack==1 & election_yr!=el_yr1
			bro yr month strike_districts strike_order strike_time treatXpost_stack mult_weight if market=="DETROIT" // just looking
			sort strike_order market ym
			
	gen treatXpost_stack_sen=treatXpost_stack if month>=9 & month<=11 & election==1
		recode treatXpost_stack_sen .=0
		replace treatXpost_stack_sen=. if t>=0 & election_yr!=el_yr1

	gen treatXpost_stack_nonsen=treatXpost_stack if (month>=9 & month<=11 & election==0) | month<9 | month==12 
		recode treatXpost_stack_nonsen .=0
		replace treatXpost_stack_sen=. if t>=0 & election_yr!=el_yr1

	*run models
	foreach o of varlist ed_ad ed_ad_pos ed_ad_neg {
		
		local controls

		reghdfe  `o' treatXpost_stack `controls' [aweight=mult_weight],  absorb(ym marketXevent) vce(cluster marketXevent) 
			eststo S_`o'_5
			
		reghdfe  `o' treatXpost_stack_sen treatXpost_stack_nonsen `controls' [aweight=mult_weight],  absorb(ym marketXevent) vce(cluster marketXevent)
			eststo S_`o'_6
			
	}			

	
esttab S_* using Output/month_level_sens.csv, replace label se keep(treatXpost treatXpost_sen treatXpost_nonsen treatXpost_ec1 treatXpost_ec1_sen treatXpost_ec1_nonsen treatXpost_stack_sen treatXpost_stack_nonsen treatXpost_stack) b(3) se(3) r2 ar2 star( + .10 * 0.05 ** 0.01 *** 0.001) nogaps


}

***SECTION 6: MONTH LEVEL FIGURES; Figure 3, Figure 4, Figure 5
if $s6 == 1 {

*Figure 4
		use "Data/strike_agenda_house_ym.dta", clear
		sort market election_yr		
		gen el_yr1_tmp = election_yr if treatXpost[_n] == 1 & treatXpost[_n-1] == 0 // this is marking the election year of the first strike 
		bysort market: egen el_yr1 = max(el_yr1_tmp)
					gen el_yr2 = el_yr1 + 2
					gen el_yr3 = el_yr1 + 4
					gen el_yr4 = el_yr1 + 6
					gen el_yr5 = el_yr1 + 8
					gen el_yr6 = el_yr1 + 10
					
		gen election_cycle = election_yr-2018
		replace election_cycle=election_cycle/2 + 6
		sort market ym
		bysort market election_cycle  : gen election_cycle_time = _n
			replace election_cycle_time = election_cycle_time + 7 if election_yr==2008
			tab election_cycle_time 
			
	*BREAK OUT TREATMENT INDICATOR ACROSS THE 24 MONTHS OF THE ELECTION CYCLE
		* this will change the election variable to be 1 for the 12 months prior to an election
			replace election =0 if month==12 & (yr==2008| yr==2010| yr==2012|yr==2014|yr==2016|yr==2018) 
			replace election =1 if month==12 & (yr==2007| yr==2009| yr==2011|yr==2013|yr==2015|yr==2017)
			drop if yr==2018 & month==12 // just checking 
			
			foreach n of numlist 12 1 2 3 4 5 6 7 8 9 10 11 {
			gen off_`n' =treatXpost_cen if month==`n' & election==0 // turn on for the month in the first year of the election cycle
				recode off_`n' .=0 //make 0 for treated months that are not this month 
				replace off_`n'=. if treatXpost==1 & election_yr!=el_yr1 //censor
			}
			
			foreach n of numlist 12 1 2 3 4 5 6 7 8 9 10 11 {
			gen on_`n' =treatXpost_cen if month==`n' & election==1 // turn on for the month in the second year of the election cycle
				recode on_`n' .=0 //make 0 for treated months that are not this month 
				replace on_`n'=. if treatXpost==1 & election_yr!=el_yr1 //censor
			}
		
	  label var on_1 "Jan." 
	  label var on_2 "Feb." 
	  label var on_3 "Mar." 
	  label var on_4  "Apr." 
	  label var on_5 "May." 
	  label var on_6 "Jun." 
	  label var on_7 "Jul." 
	  label var on_8 "Aug." 
	  label var on_9 "Sep." 
	  label var on_10 "Oct." 
	  label var on_11 "Nov." 
	  label var on_12 "Dec."

	* RUN
		reghdfe  ed_ad off* on*, absorb(ym market) vce(cluster market)
		eststo M_ed_ad_months
		coefplot M_ed_ad_months, omitted keep(on*) yline(0, lcolor(black)) vertical ///
					xtitle("Months Prior to Election")  ytitle("Strike Effect on Probability of Airing an Education Ad") graphregion(color(white)) bgcolor(white) ciopts(recast(rcap)) levels(90)   name( ed_ad_months, replace) 
			graph export Graphs/LyonKraft-Figure-4.jpg, as(jpg) replace
			
		coefplot M_ed_ad_months, omitted keep(on*) yline(0, lcolor(black)) vertical ///
					xtitle("Months Prior to Election")  ytitle("Strike Effect on Probability of Airing an Education Ad") graphregion(color(white)) bgcolor(white) ciopts(recast(rcap)) levels(90)   name( ed_ad_months, replace) scheme(plotplain)
			graph export Graphs/LyonKraft-Figure-4-BW.jpg, as(jpg) replace
		
		

 
*Figure 3, Figure 5
	*Event study, binned 
	use "Data/strike_agenda_house_ym.dta", clear
	gen neg1 = 0
	
			tab t_cen 
				gen tmpt =-1*t_cen 

			gen eventn12 = tmpt>=11 


			foreach i of num 10 8 6 4 {
				gen eventn`i' = (tmpt==`i'|  tmpt==`i'-1)
				}

			drop tmpt

			foreach i of num 0 2 4 6 8 10 {
				gen event_`i' = (t_cen ==`i' | t_cen ==`i' +1 )
				}
			gen event_12 = t_cen >=12 

foreach v of varlist ed_ad ed_ad_pos ed_ad_neg {
		preserve
		local i 0
		matrix coefs = J(400,10,.)
		local row = 1
		local col = 1 


		foreach n of numlist  0 2 4 6 8 10 {
		local ++i
			mat coefs[`row',`col'] = `n'
			
			reghdfe  `v' eventn* neg1 event_* `controls', absorb(ym market) vce(cluster market)
					mat coefs[`row',2]=_b[event_`n']
					mat coefs[`row',3]=_se[event_`n']
						local ++row
		}

		foreach n of numlist 10 8 6 4 {
		local ++i
				mat coefs[`row',`col'] = -`n'
				
			reghdfe  `v' eventn* neg1 event_* `controls', absorb(ym market) vce(cluster market)
					mat coefs[`row',2]=_b[eventn`n']
					mat coefs[`row',3]=_se[eventn`n']
						local ++row
		}


		clear
		svmat coefs
		ren coefs1 t
		ren coefs2 est_eventstudy
		ren coefs3 se_eventstudy
		foreach j in _eventstudy {
			g hi`j'=est`j'+1.645*se`j'
			g low`j'=est`j'-1.645*se`j'
			}
		drop if t==.
		drop coefs*

		set obs `=_N+1'
		recode t .=-2
		foreach j of varlist  est_eventstudy se_eventstudy  hi_eventstudy low_eventstudy {
			recode `j' .=0
				}

		 sort t
		 label var t "Months Pre/Post Strike"
		 
		graph twoway (line est_eventstudy t, xline(-2) lstyle(p1)) ///
		 (line hi_eventstudy t, lstyle(p1) lpattern(dot)) ///
		 (line low_eventstudy t, lstyle(p1) lpattern(dot)), ///
			 scheme(tufte) ///
		 yscale(range(-.1 (.1) .3)) ylabel(-.1 (.1) .3) ///
		 xscale(range(-10 (2) 10)) xlabel(-10 (2) 10) ///
		 legend(off) /// 
		 ytitle("Strike Effect on Probability of Airing an Ad") ///
		 name(es_tcen_`v',replace)
		 graph export Graphs/es_tcen_`v'.jpg, as(jpg) replace
		 restore
}	
}

***SECTION 7: FALSIFICATION; Table 5
if $s7 == 1 {
use "Data/strike_agenda_house_ym.dta", clear

	gen formidest_ad = iran_ad + iraq_ad + mideast_ad + terror_ad
	replace formidest_ad =1 if formidest_ad>1 & formidest_ad!=.
		
	*control mean
	foreach v of varlist vet_ad  farm_ad  energy_ad formidest_ad {
	sum `v' if treatXpost_cen==0
	sum `v' if treatXpost_cen==0 & sen==1
	sum `v' if treatXpost_cen==0 & sen==0
	}

	*models 
	foreach v of varlist  vet_ad farm_ad energy_ad formidest_ad {

		reghdfe  `v' treatXpost_cen, absorb(ym market) vce(cluster market)
		eststo F_`v'_1
		
		reghdfe  `v' treatXpost_cen_sen treatXpost_cen_nonsen , absorb(ym market) vce(cluster market)
		eststo F_`v'_2
		
	esttab F_* using Output/false_month_level.csv, replace label se keep(treatXpost_cen treatXpost_cen_sen treatXpost_cen_nonsen ) b(3) se(3) r2 ar2 star( + .10 * 0.05 ** 0.01 *** 0.001) nogaps
	}

}

***SECTION 8: MONTH LEVEL HETEROGENEITY; Figure A5, Table 2, Table 3, Table A4, Table A13
if $s8 == 1 {
use "Data/strike_agenda_house_ym_hetero.dta", clear
estimates clear


*Table 3, Table A13
	sum dem_voteshare rep_voteshare
	tab yr if dem_voteshare!=.

		*use baseline
		gen rep_2006_tmp = rep_voteshare if yr==2007
			bysort market: egen rep_2006=max(rep_2006_tmp)
			replace rep_voteshare= rep_2006
			
		gen dem_2006_tmp = dem_voteshare if yr==2007
			bysort market: egen dem_2006=max(dem_2006_tmp)
			replace dem_voteshare= dem_2006
			*/
		
		gen battleground=( (rep_voteshare>=.48 & rep_voteshare<=.52)|(dem_voteshare>=.48 & dem_voteshare<=.52) ) if rep_voteshare!=.
		gen htXbattleground= treatXpost_cen*battleground
		
		gen repdom=(rep_voteshare>.52 & rep_voteshare!=.) if rep_voteshare!=.
		gen htXrepdom= treatXpost_cen*repdom 
				
		gen demdom=(dem_voteshare>.52 & dem_voteshare!=.) if rep_voteshare!=.
		gen htXdemdom= treatXpost_cen*demdom
				
	*baseline means
		foreach v of varlist ed_ad ed_ad_pos ed_ad_neg   {
			sum `v' if treatXpost_cen==0 & repdom!=.
			sum `v' if treatXpost_cen==0 & battleground==1
			sum `v' if treatXpost_cen==0 & repdom==1
			sum `v' if treatXpost_cen==0 & demdom==1
		}
		
		gen formidest_ad = iran_ad + iraq_ad + mideast_ad + terror_ad
		replace formidest_ad =1 if formidest_ad>1 & formidest_ad!=.
		sum vet_ad  farm_ad  energy_ad formidest_ad if repdom!=. & treatXpost_cen==0 // baseline means with this sample

		
		estimates clear
		foreach v of varlist ed_ad ed_ad_pos ed_ad_neg ed_ad_dem* ed_ad_rep* vet_ad  farm_ad  energy_ad formidest_ad {
			
		* main model 
		reghdfe  `v' treatXpost_cen if repdom!=., absorb(ym market) vce(cluster market)
			eststo H_`v'_1

		reghdfe `v' htX* repdom demdom battleground , absorb(ym market) vce(cluster market)
			eststo H_`v'_dum_2
			test  (htXrepdom = htXbattleground)
			estadd scalar p_value = r(p)
			test (htXdemdom = htXbattleground)
			estadd scalar p_value2 = r(p)
			
				}
				
		esttab H_* using Output/month_level_het.csv, replace label se b(3) se(3) star( + .10 * 0.05 ** 0.01 *** 0.001) nogaps nocon scalar("p_value Joint F-Test" "p_value2 Joint F-Test" )


*Table C1
	use "Data/strike_agenda_house_ym_hetero.dta", clear
	replace indiv =. if strike_order!=1
	replace coor =. if strike_order!=1
	bysort market: egen indiv_tmp=max(indiv)
	recode indiv_tmp .=0 
	bysort market: egen coor_tmp=max(coor)
	recode coor_tmp .=0

	gen treatXpost_cenXindiv = treatXpost_cen*indiv_tmp
	gen treatXpost_cenXcoor = treatXpost_cen*coor_tmp

		replace totalduration =. if strike_order!=1 // this is for markets that have multiple strikes in the same election cycle

		ttest totalduration, by(coor)

	*how many 
	unique market if treatXpost_cenXcoor==1 

	foreach v of varlist ed_ad ed_ad_pos ed_ad_neg  {
		reghdfe  `v' treatXpost_cen, absorb(ym market) vce(cluster market)
			eststo H_`v'_2
		
		reghdfe  `v' treatXpost_cenXindiv treatXpost_cenXcoor , absorb(ym market) vce(cluster market)
		eststo H_`v'_2
		test treatXpost_cenXindiv = treatXpost_cenXcoor
			estadd scalar p_value = r(p)
	}

	*/

*strike intensity
use "Data/strike_agenda_house_ym_hetero.dta", clear
sum totalduration strike_stu strike_stu_days

*Figure A5 The Distribution of Strike Duration
	replace totalduration =. if strike_order!=1 // this is for markets that have multiple strikes in the same election cycle
	label var totalduration "Length of Strike (Days)"
	hist totalduration, freq xline(5 10) bin(35) ylabel(, nogrid) xlabel(,nogrid)
		graph export "Graphs/duration.jpg", replace 
		
*Figure A6
	*distribution of strike length and district size
		label var strike_stu "District Size (Students)"
		format strike_stu %15.0gc
	graph twoway (scatter strike_stu totalduration ) , ///
	legend(off )  ///
		 ytitle("District Size (Students)") ///
		 name("durationandsize",replace)
		graph export "Graphs/durationandsize.jpg", replace 
		pwcorr totalduration strike_stu, sig

*Cleaning for Table 2	
	bysort market: egen dur_tmp=max(totalduration)
		recode dur_tmp .=0 
	gen treatXpost_cenXdur = treatXpost_cen*dur_tmp
		
	*1-5, 6-10, more than 10 days
	gen treatXpost_cen_5d = (treatXpost_cenXdur<=5 & treatXpost_cenXdur!=0)
		label var treatXpost_cen_5d "Effect of 1 Week or Less Strikes"
	gen treatXpost_cen_10d = (treatXpost_cenXdur>5 & treatXpost_cenXdur<=10 & treatXpost_cenXdur!=.)
		label var treatXpost_cen_10d "Effect of 2 Week Strikes"
	gen treatXpost_cen_11pd = (treatXpost_cenXdur>10 & treatXpost_cenXdur!=.)
		label var treatXpost_cen_11pd "Effect of 3+ Week Strikes"

	foreach v of varlist treatXpost_cen_5d treatXpost_cen_10d treatXpost_cen_11pd {
		replace `v'=. if treatXpost_cen==.
	}
	
		bysort market: egen ever5d=max(treatXpost_cen_5d)
		bysort market: egen ever10d=max(treatXpost_cen_10d)
		bysort market: egen ever11pd=max(treatXpost_cen_11pd)
		recode totalduration (0/5=0 "5 Days or Less") (5.1/10=1 "5-10 Days") (10.1/34.5=2 "More than 10 Days"), gen(cat_dur)
*Table A3
	eststo clear
		foreach v of varlist per_unemployed med_income per_white per_whtnh per_hisp per_blck per_ntv per_asnpi per_othrac per_ownchld per_insch gdp dem_voteshare rep_voteshare oth_voteshare strike_stu {
		eststo sumt_`v'2: estpost summarize `v' if cat_dur==0 
		eststo sumt_`v'3: estpost summarize `v' if cat_dur==1 
		eststo sumt_`v'4: estpost summarize `v' if cat_dur==2 

		oneway `v' cat_dur, tab scheffe 
		regress `v' i.cat_dur 
			eststo `v'_d
		}

		esttab sumt* using Output/lenth_desc.csv, replace label cell("mean")
		esttab *_d using Output/length_descSE.csv, replace label se b(3) se(3) r2 ar2 star( + .10 * 0.05 ** 0.01 *** 0.001) nogaps 


*Cleaning for Table A4
	*students affected
	*number 
	sum strike_stu, detail
		replace strike_stu =. if strike_order!=1
		bysort market: egen stu_tmp=max(strike_stu)
			recode stu_tmp .=0 
		sum strike_stu, detail
		gen treatXpost_cenXstu = treatXpost_cen*stu_tmp
		
		gen treatXpost_cen_slow = (treatXpost_cenXstu<= 11707  & treatXpost_cenXstu!=0)
			replace treatXpost_cen_slow=. if treatXpost_cen==.

		gen treatXpost_cen_shigh = (treatXpost_cenXstu> 11707  & treatXpost_cenXstu!=.)
			replace treatXpost_cen_shigh =. if treatXpost_cen==.
		drop *tmp
			
	*percent affected, this is the  sum of all the students in striking districts as a percent of the population in that media market, estimates can go above 1 because a county could overlap a lot of districts, some of which are really populous, even if the county itself is not very populous. Districts could also, theoretically, be repeated because a district could overlap multiple counties within a media market, but the only crosswalk is through counties.  
	replace per_affected =. if strike_order!=1
	sum per_affected, detail
		local median `r(p50)'
		local p33 .0029906 
		local p66 .035998
		bysort market: egen stu_tmp=max(per_affected)
			recode stu_tmp .=0 
		sum per_affected, detail
		gen treatXpost_cenXpa = treatXpost_cen*stu_tmp
		
		gen treatXpost_cen_psalow = (treatXpost_cenXpa<=`p33'  & treatXpost_cenXpa!=0)
			replace treatXpost_cen_psalow=. if treatXpost_cen==.

		gen treatXpost_cen_psamid = (treatXpost_cenXpa>`p33'  & treatXpost_cenXpa<=`p66')
			replace treatXpost_cen_psamid =. if treatXpost_cen==.
			
		gen treatXpost_cen_psahigh = (treatXpost_cenXpa>`p66'  & treatXpost_cenXpa!=.)
			replace treatXpost_cen_psahigh =. if treatXpost_cen==.
			
	drop *tmp
		
	*percent inschool 
	replace per_insch =. if strike_order!=1 // we want to keep the percent in school for just the timing of the strike
	sum per_insch, detail
		local median `r(p50)'
		local p33 .243795 
		local p66 .264895
		bysort market: egen stu_tmp=max(per_insch)
			recode stu_tmp .=0 

		gen treatXpost_cenXpis = treatXpost_cen*stu_tmp
		
		gen treatXpost_cen_pislow = (treatXpost_cenXpis<=`p33'  & treatXpost_cenXpis!=0)
			replace treatXpost_cen_pislow=. if treatXpost_cen==.

		gen treatXpost_cen_pismid = (treatXpost_cenXpis>`p33'  & treatXpost_cenXpis<=`p66')
			replace treatXpost_cen_pismid =. if treatXpost_cen==.
			
		gen treatXpost_cen_pishigh = (treatXpost_cenXpis>`p66'  & treatXpost_cenXpis!=.)
			replace treatXpost_cen_pishigh =. if treatXpost_cen==.
			

			
	foreach v of varlist ed_ad ed_ad_pos ed_ad_neg  {
	*Table 2
		reghdfe  `v'  treatXpost_cen_5d treatXpost_cen_10d treatXpost_cen_11pd , absorb(ym market) vce(cluster market)
			eststo H_`v'_10
			test treatXpost_cen_5d=treatXpost_cen_10d=treatXpost_cen_11pd
			estadd scalar p_value = r(p)
			
	*Table A4
		reghdfe  `v' treatXpost_cen_slow treatXpost_cen_shigh, absorb(ym market) vce(cluster market)
			eststo H_`v'_7	
			test treatXpost_cen_slow = treatXpost_cen_shigh
			estadd scalar p_value = r(p)
			
		reghdfe  `v' treatXpost_cen_psalow treatXpost_cen_psamid treatXpost_cen_psahigh, absorb(ym market) vce(cluster market)
			eststo H_`v'_11
			test treatXpost_cen_psalow = treatXpost_cen_psamid = treatXpost_cen_psahigh
			estadd scalar p_value = r(p)
			
		reghdfe  `v' treatXpost_cen_pislow treatXpost_cen_pismid treatXpost_cen_pishigh, absorb(ym market) vce(cluster market)
			eststo H_`v'_12
			test treatXpost_cen_pislow = treatXpost_cen_pismid = treatXpost_cen_pishigh
			estadd scalar p_value = r(p)

	}

esttab H_* using Output/month_level_het.csv, replace label se b(3) se(3) r2 ar2 star( + .10 * 0.05 ** 0.01 *** 0.001) nogaps scalar("p_value Joint F-Test" )


}

***SECTION 9: COST EXTENSION; Table A6
if $s9 == 1 {
use "Data/strike_agenda_house_ym.dta", clear
	*inverse hyperbolic sine transformation; 
	gen est_cost_ed_ihst= ln(est_cost_ed+(est_cost_ed^2+1)^1/2) 

	*extensive margin
	gen anyspend = (est_cost_ed>0)
		replace anyspend=. if est_cost_ed==.
		
	*intensive margin 
	gen est_cost_ed_int = est_cost_ed
		replace est_cost_ed_int=. if est_cost_ed_int==0
		hist est_cost_ed_int // really skewed 
	gen est_cost_ed_intln=ln(est_cost_ed)
	hist est_cost_ed_intln
		
	
*2wayFE
	estimates clear

	foreach v of varlist  est_cost_ed_ihst anyspend  est_cost_ed_intln {
		
	* censored after the first strike's election cycle is up 
		reghdfe  `v' treatXpost_cen , absorb(ym market) vce(cluster market)
		eststo M_`v'_6
		
	* censored after the first strike's election cycle is up, senstiive and non-sensitive time periods separate too   
		reghdfe  `v' treatXpost_cen_sen treatXpost_cen_nonsen , absorb(ym market) vce(cluster market)
		eststo M_`v'_7
		test treatXpost_cen_sen = treatXpost_cen_nonsen 
					estadd scalar p_value = r(p)

		
	esttab M_* using Output/cost_ext.csv, replace label se scalar("p_value Joint F-Test")  keep(treatXpost_cen treatXpost_cen_sen treatXpost_cen_nonsen ) b(3) se(3) r2 ar2 star( + .10 * 0.05 ** 0.01 *** 0.001) nogaps

}
}

***SECTION 10: ADDING MEDIA MARKET AND TIME-VARYING CONTROLS, Table A10, Table A11
if $s10 == 1 {
use "Data/strike_agenda_house_ym_hetero.dta", clear
	gen month_tone = count_pos/count_ads 
		replace month_tone=0 if count_ads==0
	
	gen formidest_ad = iran_ad + iraq_ad + mideast_ad + terror_ad
	replace formidest_ad =1 if formidest_ad>1 & formidest_ad!=.
	
	
	estimates clear
	foreach v of varlist ed_ad ed_ad_pos ed_ad_neg   {
		*control for number of ads 
		reghdfe  `v' treatXpost_cen count_ads, absorb(ym market) vce(cluster market)
			eststo R_`v'_1
		 
		reghdfe  `v' treatXpost_cen_sen treatXpost_cen_nonsen count_ads, absorb(ym market) vce(cluster market)
			eststo R_`v'_2
			
		*control for other types of ads:  vet_ad energy_ad formidest_ad farm_ad
		reghdfe  `v' treatXpost_cen  vet_ad energy_ad formidest_ad farm_ad, absorb(ym market) vce(cluster market)
			eststo R_`v'_1a
		 
		reghdfe  `v' treatXpost_cen_sen treatXpost_cen_nonsen vet_ad energy_ad formidest_ad farm_ad, absorb(ym market) vce(cluster market)
			eststo R_`v'_2a
		
		*control for general positivity of the tone of the ads that month
			reghdfe  `v' treatXpost_cen month_tone , absorb(ym market) vce(cluster market)
			eststo R_`v'_3
		 
		reghdfe  `v' treatXpost_cen_sen treatXpost_cen_nonsen month_tone , absorb(ym market) vce(cluster market)
			eststo R_`v'_4
			
		*control for total ad spending	
		reghdfe  `v' treatXpost_cen est_cost, absorb(ym market) vce(cluster market)
			eststo R_`v'_5
		 
		reghdfe  `v' treatXpost_cen_sen treatXpost_cen_nonsen est_cost, absorb(ym market) vce(cluster market)
			eststo R_`v'_6
			
		*control for all media market by month controls 
		reghdfe  `v' treatXpost_cen est_cost month_tone vet_ad energy_ad formidest_ad farm_ad count_ads, absorb(ym market) vce(cluster market)
			eststo R_`v'_6a
		 
		reghdfe  `v' treatXpost_cen_sen treatXpost_cen_nonsen est_cost month_tone vet_ad energy_ad formidest_ad farm_ad count_ads, absorb(ym market) vce(cluster market)
			eststo R_`v'_6b
			
		*control for racial demographics 
		reghdfe  `v' treatXpost_cen per_white  per_blck , absorb(ym market) vce(cluster market)
			eststo R_`v'_7
		 
		reghdfe  `v' treatXpost_cen_sen treatXpost_cen_nonsen per_white  per_blck , absorb(ym market) vce(cluster market)
			eststo R_`v'_8
			
		*control for economic characteristics 
		reghdfe  `v' treatXpost_cen med_income per_unemployed  gdp, absorb(ym market) vce(cluster market)
			eststo R_`v'_9
		 
		reghdfe  `v' treatXpost_cen_sen treatXpost_cen_nonsen med_income per_unemployed  gdp, absorb(ym market) vce(cluster market)
			eststo R_`v'_10
			
		*control for parental status
		reghdfe  `v' treatXpost_cen per_ownchld, absorb(ym market) vce(cluster market)
			eststo R_`v'_11
		 
		reghdfe  `v' treatXpost_cen_sen treatXpost_cen_nonsen per_ownchld , absorb(ym market) vce(cluster market)
			eststo R_`v'_12
		
		*control for school interaction	
		reghdfe  `v' treatXpost_cen per_insch, absorb(ym market) vce(cluster market)
			eststo R_`v'_13
		 
		reghdfe  `v' treatXpost_cen_sen treatXpost_cen_nonsen per_insch, absorb(ym market) vce(cluster market)
			eststo R_`v'_14
			
		*control for all demographics together
		reghdfe  `v' treatXpost_cen per_white  per_blck per_ownchld per_insch med_income per_unemployed  gdp, absorb(ym market) vce(cluster market)
			eststo R_`v'_15
		 
		reghdfe  `v' treatXpost_cen_sen treatXpost_cen_nonsen per_white  per_blck per_ownchld per_insch med_income per_unemployed  gdp, absorb(ym market) vce(cluster market)
			eststo R_`v'_16
		
	
	}	
esttab R_* using Output/month_controls.csv, replace label se keep(treatXpost_cen treatXpost_cen_sen treatXpost_cen_nonsen ) b(3) se(3) r2 ar2 star( + .10 * 0.05 ** 0.01 *** 0.001) nogaps	
	
}

***SECTION 11: ANALYSIS OF DOWNSTREAM POLITICAL CONSEQUENCES; Table 4
if $s11 == 1 {

	*CCES Analysis
	use "Data/ccesstrike_clean.dta", clear
		estimates clear
			local controls i.educ i.faminc i.race i.gender i.has_child
	
			reghdfe  incred ctreatXpost  [aweight=weight_cumulative] , absorb(zipcode year) vce(cluster zipcode)  
				eststo m_incred1
				predict phat2
			
			reghdfe  incred ctreatXpost##i.dem  [aweight=weight_cumulative], absorb(zipcode year) vce(cluster zipcode)  
				eststo m_incred2
				
			reghdfe  incred  ctreatXpost_5d ctreatXpost_10d ctreatXpost_11pd  [aweight=weight_cumulative], absorb(zipcode year) vce(cluster zipcode)
				eststo m_incred_2
				test ctreatXpost_5d=ctreatXpost_10d=ctreatXpost_11pd
				estadd scalar p_value = r(p)
			
			reghdfe  incred  ctreatXpost_5d ctreatXpost_10d ctreatXpost_11pd if dem==0  [aweight=weight_cumulative], absorb(zipcode year) vce(cluster zipcode)
			eststo m_incred_5
			test ctreatXpost_5d=ctreatXpost_10d=ctreatXpost_11pd
			estadd scalar p_value = r(p)
			
			reghdfe  incred  ctreatXpost_5d ctreatXpost_10d ctreatXpost_11pd if dem==1  [aweight=weight_cumulative], absorb(zipcode year) vce(cluster zipcode)
			eststo m_incred_6
			test ctreatXpost_5d=ctreatXpost_10d=ctreatXpost_11pd
			estadd scalar p_value = r(p)
			
		
			*add controls
			reghdfe  incred ctreatXpost `controls'  [aweight=weight_cumulative] , absorb(zipcode year) vce(cluster zipcode)  
				eststo mc_incred1
			
			reghdfe  incred ctreatXpost##i.dem `controls'  [aweight=weight_cumulative], absorb(zipcode year) vce(cluster zipcode)  
				eststo mc_incred2
		
			reghdfe  incred ctreatXpost_5d ctreatXpost_10d ctreatXpost_11pd `controls' [aweight=weight_cumulative] , absorb(zipcode year) vce(cluster zipcode)
			eststo mc_incred_3
			test ctreatXpost_5d=ctreatXpost_10d=ctreatXpost_11pd
			estadd scalar p_value = r(p)
			

			reghdfe  incred ctreatXpost_5d ctreatXpost_10d ctreatXpost_11pd `controls' if dem==0 [aweight=weight_cumulative] , absorb(zipcode year) vce(cluster zipcode)
			eststo mc_incred_5
			test ctreatXpost_5d=ctreatXpost_10d=ctreatXpost_11pd
			estadd scalar p_value = r(p)
			
			
			reghdfe  incred ctreatXpost_5d ctreatXpost_10d ctreatXpost_11pd `controls' if dem==1 [aweight=weight_cumulative] , absorb(zipcode year) vce(cluster zipcode)
			eststo mc_incred_6
			test ctreatXpost_5d=ctreatXpost_10d=ctreatXpost_11pd
			estadd scalar p_value = r(p)
		*/
		
		esttab m_* mc* using Output/censored.csv, keep(ctreatXpost* 1.ctreat* ) replace label se scalar("p_value Joint F-Test")  ///
			b(3) se(3) star( + .10 * 0.05 ** 0.01 *** 0.001) nogaps
			*/
			
			
	estimates clear

		
}

***SECTION 12: DOWNSTREAM SPENDING HETEROGENEITY; Table A7, Table C2 
if $s12 == 1 {
	use Data/strikedistrictall, clear
	
	*spending dosage 
	estimates clear 
	label var totalduration "Length of Strike (Days)"
	bysort leaid: egen dur_tmp=max(totalduration)
		recode dur_tmp .=0 
	gen treatXpostXdur = treatXpost*dur_tmp
	gen treatXpost_5d = (treatXpostXdur<=5 & treatXpostXdur!=0)
		label var treatXpost_5d "Effect of 1 Week or Less Strikes"
	gen treatXpost_10d = (treatXpostXdur>5 & treatXpostXdur<=10 & treatXpostXdur!=.)
		label var treatXpost_10d "Effect of 2 Week Strikes"
	gen treatXpost_11pd = (treatXpostXdur>10 & treatXpostXdur!=.)
		label var treatXpost_11pd "Effect of 3+ Week Strikes"

	foreach v of varlist treatXpost_5d treatXpost_10d treatXpost_11pd {
		replace `v'=. if treatXpost==.
	}
	
		*indiv/coordinated
	gen indivstrike_treatpost = treatXpost
	replace indivstrike_treatpost=0 if	coorstrike_treatpost==1
		

	*DD 
local controls member 
		foreach v of varlist r_rev_tot_pp r_exp_perpupil r_rev_loc_pp r_rev_state_pp r_rev_fed_pp {		
		sum `v' if strikeever==1 & treatXpost==0
		}

		foreach v of varlist r_rev_tot_pp r_exp_perpupil r_rev_loc_pp r_rev_state_pp r_rev_fed_pp {		
*Table A7
		reghdfe `v' treatXpost `controls' , absorb(year leaid) vce(cluster leaid)
				est sto est_`v'1
				
		reghdfe `v' treatXpost_5d treatXpost_10d treatXpost_11pd  `controls' , absorb(year leaid) vce(cluster leaid)
				est sto est_`v'2
				test treatXpost_5d=treatXpost_10d=treatXpost_11pd
				estadd scalar p_value = r(p)
*Table C2
		reghdfe `v' coorstrike_treatpost indivstrike_treatpost  `controls' , absorb(year leaid) vce(cluster leaid)
				est sto est_`v'3
				test coorstrike_treatpost=indivstrike_treatpost
				estadd scalar p_value = r(p)	
		
		}
		
		esttab est_* using Output/financedos.csv, replace label se b(3) se(1) star( + .10 * 0.05 ** 0.01 *** 0.001) nogaps scalar("p_value Joint F-Test")
*

}

***SECTION 13: DOWNSTREAM SPENDING CONSEQUENCES; Figure 6
if $s13 == 1 {
		use Data/strikedistrictall, clear
		set scheme tufte 
		foreach v of varlist r_rev_tot_pp r_exp_perpupil {	
		estimates clear
		use Data/strikedistrictall, clear

	drop t

	rename `v' Y
	rename leaid i 
	rename year t
	rename strike_year Ei
	gen K = t-Ei 								
	gen D = K>=0 & Ei!=. 						
	
	keep K Y i t Ei D member
	
	*analysis
		local controls member 
	

* Estimation with csdid of Callaway and Sant'Anna (2020)
local z : variable label Y
gen gvar = cond(Ei==., 0, Ei) // group variable as required for the csdid command
csdid Y member, ivar(i) time(t) gvar(gvar) notyet  // 
estat event, window(-3 4) estore(cs`v') // this produces and stores the estimates at the same time
event_plot cs`v',  graph_opt(xline(-1, lstyle(p1)) yline(0, lstyle(p1)) graphregion(color(white)) bgcolor(white) ylabel( -1000 (500) 1500, angle(horizontal)) xtitle("Years Pre/Post Strike") ytitle("`z'") xlabel(-3(1)4) ) lag_opt(color(black) msymbol(none)) lead_opt(color(black) msymbol(none)) ciplottype(rline) lag_ci_opt( color(none) lstyle(p1) lpattern(dot)) lead_ci_opt(color(white) lstyle(p1) lpattern(dot)) legend_opt(row(1) order( 1 2 ) label(1 "Estimate") label(2 "95% Confidence Interval") )  stub_lag(Tp#) stub_lead(Tm#) together  
				graph export Graphs/`v'_cs.jpg, as(jpg) replace
}

esttab cs* using "Output/cstest.csv", replace label se b(0) se(0) star( + 0.10 * 0.05 ** 0.01 *** 0.001) nogaps
} 
	
***SECTION 14: DOWNSTREAM SPENDING CONSEQUENCES ROBUSTNESS; Table A12
if $s14 == 1 {
		use Data/strikedistrictall, clear

		* event study dummies, first strike
				gen neg1 = 0
				gen tmpt =-1*t

				gen eventn4 = tmpt>=4

				foreach i of num 3/2 {
				gen eventn`i' = tmpt==`i' 
				}

				drop tmpt

				foreach i of num 0/4 {
				gen event_`i' = t==`i' 
				}
				gen event_5 = t>=5

		*state
			bysort state_abbrev: egen strikestate=max(strikeever)
			gen spillover=(strikestate==0 | strikeever==1)
				
		*analysis
		estimates clear
		local controls member 
		
			*quick mean imputation with controls
			foreach v of varlist percentschagepoverty percentspeced percentell {
			bysort leaid: egen dis_`v' = mean(`v')
			replace `v'= dis_`v' if `v'==. //impute w/ zipcode modal values
			egen all_`v'= mean(`v')
			replace `v'= all_`v' if `v'==. // impute w/ overall modal values if no obs from that district 
		}
		
		
		estimates clear
		foreach v of varlist r_exp_perpupil r_rev_tot_pp { // r_rev_loc_pp r_rev_state_pp r_rev_fed_pp {	
		preserve
			*CS_Model
			drop t
			rename `v' Y
			rename leaid i 
			rename year t
			rename strike_year Ei
			gen K = t-Ei 								
			gen D = K>=0 & Ei!=. 						
			keep K Y i t Ei D member percentschagepoverty percentspeced percentell spillover
			gen gvar = cond(Ei==., 0, Ei) 
			csdid Y member, ivar(i) time(t) gvar(gvar) notyet  
			estat event, window(-3 4) estore(rob`v'0) 
			
			*CS with sociodemographic controls 
			csdid Y member percentschagepoverty percentspeced percentell , ivar(i) time(t) gvar(gvar) notyet  
			estat event, window(-3 4) estore(rob`v'2) 
			
			keep if spillover==1
			*CS spillover
			csdid Y member , ivar(i) time(t) gvar(gvar) notyet  
			estat event, window(-3 4) estore(rob`v'3) 
			
		restore 
			
			*traditional, not C&S
			reghdfe `v' eventn* neg1 event_* `controls'  , absorb(year leaid) vce(cluster leaid)
			eststo rob`v'1
		*/	
		}
esttab rob* using "Output/finance_rob.csv", replace label se b(0) se(0) star( * 0.05 ** 0.01 *** 0.001) nogaps	

		}
		
***SECTION 15: Drop Spillover Markets, Table A8
if $s15 == 1 {
	use "Data/strike_agenda_house_ym_border.dta", clear

*2wayFE
	estimates clear

	foreach v of varlist ed_ad ed_ad_pos ed_ad_neg {
	
	* main model
		reghdfe  `v' treatXpost_cen, absorb(ym market) vce(cluster market)
		eststo M_`v'_0
	
	preserve
	replace bortreatXpost_cen=0 if treatXpost_cen==1
	reghdfe  `v' treatXpost_cen if bortreatXpost_cen!=1 , absorb(ym market) vce(cluster market)
		eststo M_`v'_3
		
	reghdfe  `v' treatXpost_cen_sen treatXpost_cen_nonsen if bortreatXpost_cen!=1 , absorb(ym market) vce(cluster market)
			eststo M_`v'_4
	restore

	esttab M_* using Output/border.csv, replace label se keep(treatXpost_cen treatXpost_cen_sen treatXpost_cen_nonsen ) b(3) se(3) r2 ar2 star( + .10 * 0.05 ** 0.01 *** 0.001) nogaps

}

}

***SECTION 16: INCUMBENT ANALYSIS; Table A5
if $s16 == 1 {
use "Data/strike_agenda_house_ym.dta", clear

	
*baseline means
	foreach v of varlist ed_ad_incum ed_ad_incum_pos ed_ad_incum_neg {
		sum `v' if treatXpost_cen==0 
		sum `v' if treatXpost_cen==0 & sens==1
		sum `v' if treatXpost_cen==0 & sens==0
	}
	
*2wayFE
	estimates clear

	foreach v of varlist ed_ad_incum ed_ad_incum_pos ed_ad_incum_neg {
		
	*main 
		reghdfe  `v' treatXpost_cen , absorb(ym market) vce(cluster market)
		eststo M_`v'_6
		
	* senstiive and non-sensitive time periods separate too   
		reghdfe  `v' treatXpost_cen_sen treatXpost_cen_nonsen , absorb(ym market) vce(cluster market)
		eststo M_`v'_7
		test treatXpost_cen_sen = treatXpost_cen_nonsen 
		
	esttab M_* using Output/month_incum.csv, replace label se keep(treatXpost_cen treatXpost_cen_sen treatXpost_cen_nonsen ) b(3) se(3) r2 ar2 star( + .10 * 0.05 ** 0.01 *** 0.001) nogaps

}

}

***SECTION 17: Union Campaign Contributions; Table A9 
if $s17 == 1 {
use "Data/finance_strike_cdyr.dta", clear
estimates clear
	sum total_ if treatXpost_cen==0 //baseline mean
	
	foreach v of varlist total_* { 
		reghdfe  `v' treatXpost_cen , absorb(st cd  election_year) vce(cluster st cd )  
			eststo m_`v'1
			
	}
			
esttab m_* using Output/cdXyear_finance.csv, replace label se keep(treatXpost_cen) b(3) se(3) r2 ar2 star( + .10 * 0.05 ** 0.01 *** 0.001) nogaps
}
	

